﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BLL
{
    public class addArea
    {
        DAL.DBbase d_DBbase = new DAL.DBbase();
        DataSet ds = new DataSet();
        //判断区域号是否存在，存在则插入，不存在则不插入
        public void jundgetArea(string modeId, string area, string facilitiesNo)
        {
            int areaRece = int.Parse(area);
            int facNoRece = int.Parse(facilitiesNo);
            ds = d_DBbase.returnDataSet("SELECT distinct area from modeArea where modeId = '" + modeId + "'");
            int count = ds.Tables["area"].Rows.Count;
            int[] areaFromDb = new int[count];
            int[] facNoFromDb = new int[count];
            int i = 0;
            int temp = 0;
            foreach (DataRow row in ds.Tables["area"].Rows)
            {
                areaFromDb[i] = int.Parse(row[0].ToString());
                facNoFromDb[i] = int.Parse(row[1].ToString());
                i++;
            }
            for (int j = 0; j < i; j++)
            {
                if (areaFromDb[j] == areaRece)
                {
                    if (facNoFromDb[j] == facNoRece)
                    {
                        temp = 1;
                        break;
                    }
                }
                else
                {
                    temp = 0;
                }
            }
            if (temp == 0)
            {
                d_DBbase.ExecuteNonQuery("insert into modeArea(modeId,area) values (" + modeId + "," + area + ") ");
            }
        }
    }
}
